package jiaxa.com.setting;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private CheckBox chkChecked;
    private SharedPreferences sp;
    private EditText edtName;
    private EditText edtAge;
    private EditText edtNo;
    private Button btnSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xml);

        //        chkChecked = (CheckBox) findViewById(R.id.chkChecked);
        //
        //        sp = getSharedPreferences("config", MODE_PRIVATE);
        //        boolean status = sp.getBoolean("status", false);
        //        chkChecked.setChecked(status);
        //
        //        chkChecked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        //            @Override
        //            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        //
        //                Toast.makeText(MainActivity.this,isChecked +"",Toast.LENGTH_SHORT).show();;
        //                SharedPreferences.Editor edit = sp.edit();
        //                edit.putBoolean("status",isChecked);
        //                edit.commit();
        //            }
        //        });

        edtName = (EditText) findViewById(R.id.edtName);
        edtAge = (EditText) findViewById(R.id.edtAge);
        edtNo = (EditText) findViewById(R.id.edtNo);
        btnSubmit = (Button) findViewById(R.id.btnSubmit);

        btnSubmit.setOnClickListener(new btnSubmitOnClickListener());
    }

    private class btnSubmitOnClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            String name = edtName.getText().toString().trim();
            String age = edtAge.getText().toString().trim();
            String no = edtNo.getText().toString().trim();
            if (TextUtils.isEmpty(name) || TextUtils.isEmpty(age) || TextUtils.isEmpty(no)) {
                Toast.makeText(MainActivity.this, "信息不能为空", Toast.LENGTH_SHORT).show();
                return;
            }
        }
    }
}
